﻿
/*根据屏幕适配font-size*/

// ;(function (doc, win) {
//      var docEl     = doc.documentElement,
//          resizeEvt = 'onorientationchange' in window ? 'onorientationchange' : 'resize',
//          recalc    = function () {
//              var clientWidth = docEl.clientWidth;
//              if (!clientWidth) return;
//              if(clientWidth>=750){
//                  docEl.style.fontSize = '100px';//屏幕大于750，font-size:100px;
//              }else{
//                  docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
//              }
//          };
//          setTimeout(function(){console.log($('header').height());},1);
//      if (!doc.addEventListener) return;
//      win.addEventListener(resizeEvt, recalc, false);
//      doc.addEventListener('DOMContentLoaded', recalc, false);
// })(document, window);


;(function($, window, document,undefined) {
     
    var Tfn = function() {
        this.header            = $('header'),
        this.center            = $('#wrapper'),
        this.footer            = $('footer'),
        this.windowWidth       = ('innerWidth' in window) ? window.innerWidth : document.documentElement.clientWidth,//屏幕宽度
        this.windowHeight      = ('innerHeight' in window) ? window.innerHeight : document.documentElement.clientHeight,//屏幕高度
        this.IEnum             = parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE",""));//如果是ie浏览器，ie的版本数
        this.isAnimating       = false,//判断轮播动画是否进行中
        this.isAnimating1       = false,//判断下拉动画是否进行中
        this.aniTime           = 600,  //动画时间
        this.isPc              = null,//是否为pc端
        this.appDirection      = null,//手机端触摸滑动方向
        this.support           = { animations : Modernizr.cssanimations },//是否支持1，animations
        this.animEndEventNames = {
                'WebkitAnimation' : 'webkitAnimationEnd',
                'OAnimation' : 'oAnimationEnd',
                'msAnimation' : 'MSAnimationEnd',
                'animation' : 'animationend'
            },
        this.animEndEventName = this.animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
        this.onEndAnimation    = function( el, callback ) {//动画所属元素，如果不支持animations回调函数。
            var self = this;
            var onEndCallbackFn = function( ev ) {
                if( self.support.animations ) {
                    if( ev.target != this ) return;
                    this.removeEventListener( self.animEndEventName, onEndCallbackFn );
                }
                if( callback && typeof callback === 'function' ) { callback.call(); }
            };
            if( self.support.animations ) {
                el.addEventListener( self.animEndEventName, onEndCallbackFn );
            }
            else {
                onEndCallbackFn();
            }
        };
        /*var transEndEventNames = {  
            'WebkitTransition' : 'webkitTransitionEnd',  
            'MozTransition'    : 'transitionend',  
            'OTransition'      : 'oTransitionEnd',  
            'msTransition'     : 'MSTransitionEnd',  
            'transition'       : 'transitionend'  
        },  
        this.transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ]; //transition结束事件*/
    }
     
    Tfn.prototype = {
        //初始化
        init  : function() { 

            if (!!window.ActiveXObject || "ActiveXObject" in window){$('body').addClass("ie");}
            if(this.IEnum<9){
                alert("您的浏览器版本过低，请下载IE9及以上版本");return false;
            }else if(this.IEnum==9){
                $('body').addClass("ie9");
            }else if(this.IEnum==10){
                $('body').addClass("ie10");
            }else if(this.IEnum==11){
                $('body').addClass("ie11");
            }
            this.IsPC();
            if(this.isPc){
                this.storage();
                this.loader();
                this.logoName();
            }
            this.contentInit();
            this.appNav();
            this.downMove();
            this.scrolly();
            this.dialog();
            this.toTop();
        },

        storage:function () {
           var self = this,
               loading = $('#loading'),
               stor = JSON.parse(sessionStorage.getItem('key')),
               info ={call:null};
           if(stor==null){
               info.call=1;
               sessionStorage.setItem('key',JSON.stringify(info));
           }else{
               info.call=stor.call+1;
               sessionStorage.setItem('key',JSON.stringify(info));
               loading.remove();
           }
           if(self.IEnum<10){
               loading.remove();
           }
        },

        //内容层min-height
        contentInit:function(){
            var self      = this,
                minHeight =self.windowHeight - (self.header.height() + self.footer.height());
            self.center.css('min-height',minHeight+'px');
            $('[data-hei]').each(function(index,e){
                var wid=$(this).width(),
                    hei=parseInt(wid*($(this).attr('data-hei')));
                $(this).css('height',hei+"px");
            });
            $("[data-ahref]").on('click',function () {
                var src = $(this).attr('data-ahref');
                var type = $(this).attr('data-target');
                if(type==1){
                    window.open(src);
                }else{
                    window.location.href=src;
                }
            });
        },

        //loading
        loader:function () {
            var self    = this,
                loading = $('#loading'),
                ishave = loading.length<=0 ? true : false;
            if(ishave){
                $('body').removeClass('on');
                return false
            }
            var medio   = loading.find('#water-medio'),
                mask1   = loading.find('.logo-water'),
                name    = loading.find('.logoName'),
                water   = loading.find('.load-water');
            var DOM = {};
            DOM.intro = document.querySelector('#loading');
            DOM.shape = DOM.intro.querySelector('svg.shape');
            DOM.path = DOM.shape.querySelector('path');
            setTimeout(function () {
                water.addClass('on');
            },2800);
            self.onEndAnimation(water[0],function(){
                mask1.addClass('on');
            });
            self.onEndAnimation(mask1[0],function(){
                medio[0].play();
                setTimeout(function () {
                    name.addClass('on');
                },800);
                setTimeout(function () {
                    $("html,body").animate({scrollTop:0}, 100);
                    anime({
                        targets: DOM.intro,
                        duration: 1600,
                        easing: 'easeInOutSine',
                        translateY: '-200vh'
                    });

                    anime({
                        targets: DOM.shape,
                        scaleY: [
                            {value:[0.8,1.8],duration: 800,easing: 'easeInQuad'},
                            {value:1,duration: 800,easing: 'easeOutQuad'}
                        ]
                    });

                    anime({
                        targets: DOM.path,
                        duration: 1600,
                        easing: 'easeOutQuad',
                        d: DOM.path.getAttribute('pathdata:id')
                    });
                    setTimeout(function () {
                        loading.remove();
                        $("html,body").animate({scrollTop:0}, 100);
                        $('body').removeClass('on');
                        $('#ad').click();
                    },2000);
                },8000);
                $('.load-medio').mousewheel(function(event) {
                    if(event.deltaY == -1){
                            $("html,body").animate({scrollTop:0}, 100);
                            anime({
                                targets: DOM.intro,
                                duration: 1600,
                                easing: 'easeInOutSine',
                                translateY: '-200vh'
                            });

                            anime({
                                targets: DOM.shape,
                                scaleY: [
                                    {value:[0.8,1.8],duration: 800,easing: 'easeInQuad'},
                                    {value:1,duration: 800,easing: 'easeOutQuad'}
                                ]
                            });

                            anime({
                                targets: DOM.path,
                                duration: 1600,
                                easing: 'easeOutQuad',
                                d: DOM.path.getAttribute('pathdata:id')
                            });
                        setTimeout(function () {
                            loading.remove();
                            $("html,body").animate({scrollTop:0}, 100);
                            $('body').removeClass('on');
                            $('#ad').click();
                        },2000);
                    }
                });
                $('.load-scr').on("click",function (object) {
                    $("html,body").animate({scrollTop:0}, 100);
                    anime({
                        targets: DOM.intro,
                        duration: 1600,
                        easing: 'easeInOutSine',
                        translateY: '-200vh'
                    });

                    anime({
                        targets: DOM.shape,
                        scaleY: [
                            {value:[0.8,1.8],duration: 800,easing: 'easeInQuad'},
                            {value:1,duration: 800,easing: 'easeOutQuad'}
                        ]
                    });

                    anime({
                        targets: DOM.path,
                        duration: 1600,
                        easing: 'easeOutQuad',
                        d: DOM.path.getAttribute('pathdata:id')
                    });
                    setTimeout(function () {
                        loading.remove();
                        $("html,body").animate({scrollTop:0}, 100);
                        $('body').removeClass('on');
                        $('#ad').click();
                    },2000);
                })
            });
        },

        //字体随机模糊效果
        logoName:function () {
            var name   = $('.logoName'),
                isHave = name.length <= 0 ? true : false;
            if(isHave) return false;
            for(var n=0;n<name.length;n++){
                var txt = name[n].getAttribute('data-name').split('');
                for(var i=0;i<txt.length;i++){
                    var lab = '<label class="animated scaleIn">'+txt[i]+'</label>';
                    if(i%3==0){
                        lab = '<label class="animated Txtblur1">'+txt[i]+'</label>';
                    }
                    if(i%4==0){
                        lab = '<label class="animated Txtblur2">'+txt[i]+'</label>';
                    }
                    $(name[n]).append(lab);
                }
            }
        },

        //回到顶部
        toTop:function () {
            var self      = this;
            var top_btn   = $('.toTop'),
                isHave = top_btn.length <= 0 ? true : false;
            if(isHave) return false;
            top_btn.on('click',function () {
                $("html,body").animate({scrollTop:0}, 1000);
            });
            $('.scr').on('click',function () {
                $("html,body").animate({scrollTop:(self.windowHeight-50)}, 1000);
            });
        },


        //判断是否为pc端
        IsPC:function(){
            var self = this;
            var userAgentInfo = navigator.userAgent;
            var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
            self.isPc = true;
            for (var v = 0; v < Agents.length; v++) {
                if (userAgentInfo.indexOf(Agents[v]) > 0) { self.isPc = false; break; }
            }
            return self.isPc;
        },

        //页面切换（针对setinterval）
        VisibilityChange:function ( gofn , backfn ) {
            var hiddenProperty = 'hidden' in document ? 'hidden' :
                'webkitHidden' in document ? 'webkitHidden' :
                    'mozHidden' in document ? 'mozHidden' :
                        null;
            var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
            var onVisibilityChange = function(){
                if (!document[hiddenProperty]) {
                    backfn.call();
                }else{
                    gofn.call();
                }
            };
            document.addEventListener(visibilityChangeEvent, onVisibilityChange);
        },

        //手机菜单动画
        appNav: function(){
            var self     = this,
                appNav   = $('.app-nav'),
                getApp   = appNav.find('.getAppNav'),
                appUl    = appNav.find('ol'),
                appLi    = appUl.find('li'),
                appDown  = appLi.find('.app-down'),
                appUlWid = appUl.attr('data-width'),
                showAni  = appUl.attr('data-effect'),
                hideAni  = appUl.attr('data-hideAni');
            appUl.css('width',(this.windowWidth*appUlWid)+'px');
            setTimeout(function () {
                appLi.removeClass(showAni).addClass(hideAni);
            },300);
            getApp.on('click',function(e){
                if(self.isAnimating1) return false;
                self.isAnimating1 = true;
                var isActive     = $(this).hasClass('menuActive');
                $(this).toggleClass('menuActive');
                if(isActive){
                    appLi.removeClass(showAni).addClass(hideAni);
                    for(var i=0;i<appDown.length;i++){
                        var _this = $(appDown[i]);
                        if(_this.hasClass('on')){
                            _this.removeClass('on');
                        }
                    }
                    setTimeout(function(){
                        appUl.removeClass('on');
                        self.isAnimating1 = false;
                    },300);
                }else{
                    appLi.removeClass(hideAni).addClass(showAni);
                    appUl.addClass('on');
                    setTimeout(function(){
                        self.isAnimating1 = false;
                    },self.aniTime);
                }

            });
            appLi.on('click',function (e) {
               if($(this).hasClass('child-Down')){
                   var nav = $(this).find('.app-down');
                   for(var i=0;i<appDown.length;i++){
                       var _this = $(appDown[i]);
                       if(_this.hasClass('on')&&!_this.is(nav)){
                           _this.removeClass('on');
                       }
                   }
                   nav.toggleClass('on');
               }
            });
        },

        //下拉动画
        downMove:function(){
            var self     = this,
                downBox  = $('.layout-down'),
                ishave   = downBox.length<=0 ? true : false;
            if(ishave) return false;
            if(self.isAnimating1) return false;
            var isOpen  = function(){
                    console.log("下拉");
                },//下拉时回调函数
                isClose = function(){
                    console.log("未下拉");
                };//未下拉时回调函数
            var isActive     = false;
            downBox.on('click',function(e){
                self.isAnimating1 = true;
                var isAni        = $(this).hasClass('father'),
                    txtBox       = $(this).find('.downTxt'),
                    Tdown        = $(this).parents('.layout-down'),
                    down         = $(this).find('ul'),
                    downLi       = down.find('li'),
                    showAni      = down.attr('data-effect')||'fadeInDown',
                    hideAni      = down.attr('data-hideAni')||'fadeOutDown';
                isActive     = $(this).attr('data-on')|| false;
                function downToggle(e){
                    isActive = isActive==='true'?true:false;
                    console.log(isActive);
                    if( isActive ) {
                        downLi.removeClass(showAni).addClass(hideAni);
                        self.onEndAnimation(downLi[0],function(){
                            down.hide();
                            self.isAnimating1 = false;
                        });
                        // callback on close
                        isClose( e );
                    }
                    else {
                        down.show();
                        downLi.removeClass(hideAni).addClass(showAni);

                        // callback on open
                        isOpen( e );   
                    }
                    isActive = !isActive;
                    e.parents('.layout-down').attr('data-on',isActive);
                }
                downToggle(down);
                downLi.on('click',function(){
                    var txt = $(this).html();
                    txtBox.html(txt);
                });
            });         
        },

        //单张图片切换动画(.Tpage,.moveNext,.movePrev);
        picMove:function(){
            var self = this,
                picBox = $('.component'),
                ishave = picBox.length<=0 ? true : false;
            if(ishave) return false;

            var animEndEventNames = {
                    'WebkitAnimation' : 'webkitAnimationEnd',
                    'OAnimation' : 'oAnimationEnd',
                    'msAnimation' : 'MSAnimationEnd',
                    'animation' : 'animationend'
                },
                // animation end event name
                animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
                component        = null,
                items            = null,
                current          = 0,//当前页数
                itemsCount       = null,
                navNext          = document.querySelectorAll( '.moveNext' ),
                navPrev          = document.querySelectorAll( '.movePrev' ),
                Tpage            = null,
                pageChange       = document.querySelectorAll( '.pageChange' ),//可选择页数
                TpageChange      = null,
                itemTxt          = null,//轮播文字
                loop             = null,
                loopTime         = 6000;//轮播间隔时间

            function reinit(_this,dir) {
                component  = _this.parents( '.component' )[0],//容器
                    items      = component.querySelector( 'ul.itemwrap' ).children,//图片项
                    itemsCount = items.length,
                    Tpage      = $(component.querySelector( '.Tpage' )),
                    current    = parseInt(Tpage.attr( 'data-num' )),
                    TpageChange= component.querySelectorAll( '[data-change]' );
                itemTxt    = component.querySelectorAll( '[data-txt]');
                if(dir === 'num'){
                    var Tnum   = _this.attr('data-change');
                }
                navigate( dir , Tnum);

            }
            function goloop() {
                var _this = $('[data-loop]');
                if(_this.length>0){
                    loop=setInterval(function () {
                        for(var i =0;i<_this.length;i++){
                            reinit($(_this[i]),'next');
                        }
                    },loopTime);
                }
            }

            function navigate( dir , num) {

                if( self.isAnimating) return false;
                self.isAnimating = true;
                clearInterval(loop);
                var cntAnims = 0;
                var currentItem = items[ current ];
                var currentTxt  = $(itemTxt).eq(current);
                if( dir === 'next' ) {
                    current = current < itemsCount - 1 ? current + 1 : 0;
                }
                else if( dir === 'prev' ) {
                    current = current > 0 ? current - 1 : itemsCount - 1;
                }
                else if( dir === 'num'){
                    current = parseInt(num);
                }
                Tpage.html('0'+(current+1)).attr('data-num',current);
                $(TpageChange).eq(current).addClass('on').siblings().removeClass('on');
                var nextItem = items[ current ];
                var nextTxt  = $(itemTxt).eq(current);
                var onEndAnimationCurrentItem = function() {
                    this.removeEventListener( animEndEventName, onEndAnimationCurrentItem );
                    classie.removeClass( this, 'current' );
                    currentTxt.removeClass('on txtHide');
                    classie.removeClass( this, dir === 'next' ? 'navOutNext' : 'navOutPrev' );
                    ++cntAnims;
                    if( cntAnims === 2 ) {
                        self.isAnimating = false;
                        goloop();
                    }
                }

                var onEndAnimationNextItem = function() {
                    this.removeEventListener( animEndEventName, onEndAnimationNextItem );
                    classie.addClass( this, 'current' );
                    nextTxt.addClass('on').removeClass('txtShow');
                    classie.removeClass( this, dir === 'next' ? 'navInNext' : 'navInPrev' );
                    ++cntAnims;
                    if( cntAnims === 2 ) {
                        self.isAnimating = false;
                        goloop();
                    }
                }

                if( self.support.animations ) {
                    currentItem.addEventListener( animEndEventName, onEndAnimationCurrentItem );
                    nextItem.addEventListener( animEndEventName, onEndAnimationNextItem );
                    classie.addClass( currentItem, dir === 'next' ? 'navOutNext' : 'navOutPrev' );
                    classie.addClass( nextItem, dir === 'next' ? 'navInNext' : 'navInPrev' );
                    currentTxt.addClass('txtHide');
                    nextTxt.addClass('txtShow');
                }
                else {
                    console.log('不支持css3 animated');
                    $(currentItem).hide();
                    $(nextItem).fadeIn(200);
                    setTimeout(function(){
                        classie.removeClass( currentItem, 'current' );
                        classie.addClass( nextItem, 'current' );
                        self.isAnimating = false;
                    },200)
                }
            }

            (function(){
                for(var i=0;i<navNext.length;i++){
                    navNext[i].addEventListener( 'click', function( ev ) {
                        reinit($(this),'next');
                        ev.preventDefault();
                    } );
                }
                for(var n=0;n<navPrev.length;n++){
                    navPrev[n].addEventListener( 'click', function( ev ) {
                        reinit($(this),'prev');
                        ev.preventDefault();
                    } );
                }
                for(var j=0;j<pageChange.length;j++){
                    var list = pageChange[j].querySelectorAll( '[data-change]' );
                    for(var h=0;h<list.length;h++){
                        list[h].addEventListener( 'click', function( ev ) {
                            if(this.getAttribute('data-change')!=current){
                                reinit($(this),'num');
                            }
                            ev.preventDefault();
                        } );
                    }
                }
                var gofn=function () {
                    clearInterval(loop);
                };
                var backfn=function () {
                    goloop();
                }
                self.VisibilityChange(gofn,backfn);
                goloop();
            })();
        },

        //弹窗
        dialog:function(){
            var self          = this,
                have       = $('.dialog'),
                ishave        = have.length<=0 ? true : false;
            if(ishave) return false;
            var dialogBtn     = document.querySelectorAll( '[data-dialog]' ),
                Tdialog       = null,
                closeBtn      = null,
                mask          = null,
                onOpenDialog  = function(){
                    // console.log("弹窗打开");
                    $('.wrapper').addClass('dialogMove');
                    var navItem = Tdialog.find('.nav-item');
                    if(navItem.length>0){
                        navItem.addClass('on');
                    }
                    $('#ran1').RangeSlider({ min: 0,   max: 100,  step: 1,callback: change});
                    $('#ran2').RangeSlider({ min: 0,   max: 100,  step: 1,callback: change});
                    $('#ran3').RangeSlider({ min: 0,   max: 100,  step: 1,callback: change});
                },//弹窗打开时回调函数
                onCloseDialog = function(){
                    // console.log("弹窗关闭");
                    $('.wrapper').removeClass('dialogMove');
                    var navItem = Tdialog.find('.nav-item');
                    if(navItem.length>0){
                        navItem.removeClass('on');
                    }
                };//弹窗关闭时回调函数
            function dialogToggle(e,isOpen){
                if( isOpen ) {
                    classie.remove( e, 'dialog--open' );
                    classie.add( e, 'dialog--close' );
                    self.onEndAnimation(e.querySelector( '.dialog_content' ),function(){
                        classie.remove( e, 'dialog--close' );
                        // callback on close
                        onCloseDialog( this );
                    });

                }
                else {
                    classie.add( e, 'dialog--open' );
                    // callback on open
                    onOpenDialog( this );
                }
                isOpen = !isOpen;
                e.setAttribute('data-isOpen',isOpen);
            }
            (function(){
                for(var i=0;i<dialogBtn.length;i++){
                    var e = $(dialogBtn[i]);
                    e.on('click',function () {
                        Tdialog  = $("#"+$(this).attr( 'data-dialog' ));
                        closeBtn = Tdialog.find('[data-dialog-close]');
                        mask     = Tdialog.find( '.dialog_mask' );
                        var isOpen  = (Tdialog.attr('data-isOpen') == 'true') || false;
                        var isclick = Tdialog.attr('data-isclick');
                        dialogToggle(Tdialog[0],isOpen);
                        if(isclick == undefined){
                            closeBtn.on('click',function () {
                                dialogToggle($(this).parents('.dialog')[0],true);
                            });
                            mask.on('click',function () {
                                dialogToggle($(this).parents('.dialog')[0],true);
                            });
                            Tdialog.attr('data-isclick','true');
                        }

                    })

                }
            })()
        },

        //transform滚动惯性视差（背景滚动视差）
        scrolly:function () {
            var defaults = {
                wrapper: '#scrolly',
                parent_move : true,//容器跟随惯性滚动
                targets : '.scrolly-el',
                bgParallax : false,//背景惯性滚动
                wrapperSpeed: 0.08,
                targetSpeed: 0.02,
                targetPercentage: 0.1
            };
            var requestAnimationFrame =
                window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
            window.requestAnimationFrame = requestAnimationFrame;
            var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
            var extend = function () {
                // Variables
                var extended = {};
                var deep = false;
                var i = 0;
                var length = arguments.length;
                // Merge the object into the extended object
                var merge = function (obj) {
                    for (var prop in obj) {
                        if (obj.hasOwnProperty(prop)) {
                            extended[prop] = obj[prop];
                        }
                    }
                };
                // Loop through each object and conduct a merge
                for ( ; i < length; i++ ) {
                    var obj = arguments[i];
                    merge(obj);
                }

                return extended;

            };
            var scrolly = function(){
                this.Targets = [];
                this.TargetsLength = 0;
                this.wrapper = '';
                this.windowHeight = 0;
                this.wapperOffset = 0;
            };
            scrolly.prototype = {
                isAnimate: false,
                isResize : false,
                scrollId: "",
                resizeId: "",
                init : function(options){
                    this.settings = extend(defaults, options || {});
                    this.wrapper = document.querySelector(this.settings.wrapper);

                    if(this.wrapper==="undefined"){
                        return false;
                    }
                    this.targets = document.querySelectorAll(this.settings.targets);
                    document.body.style.height = this.wrapper.clientHeight + 'px';

                    this.windowHeight = window.clientHeight;
                    this.attachEvent();
                    this.apply(this.targets,this.wrapper);
                    this.animate();
                    this.resize();
                },
                apply : function(targets,wrapper){
                    if(this.settings.parent_move){
                        this.wrapperInit();
                    }
                    this.targetsLength = targets.length;
                    for (var i = 0; i < this.targetsLength; i++) {
                        var attr = {
                            offset : targets[i].getAttribute('data-offset'),
                            speedX : targets[i].getAttribute('data-speed-x'),
                            speedY : targets[i].getAttribute('data-speed-Y'),
                            percentage : targets[i].getAttribute('data-percentage'),
                            horizontal : targets[i].getAttribute('data-v'),
                            type : targets[i].getAttribute('data-type')
                        };
                        this.targetsInit(targets[i],attr);
                    }
                },
                wrapperInit: function(){
                    this.wrapper.style.width = '100%';
                    this.wrapper.style.position = 'fixed';
                },
                targetsInit: function(elm,attr){

                    this.Targets.push({
                        elm : elm,
                        offset : attr.offset ? attr.offset : 0,
                        offsetTop : $(elm).offset().top,
                        hei : $(elm).height(),
                        horizontal : attr.horizontal ? attr.horizontal : 0,
                        type : attr.type ? attr.type : 0,
                        top : 0,
                        left : 0,
                        speedX : attr.speedX ? attr.speedX : 1,
                        speedY : attr.speedY ? attr.speedY : 1,
                        percentage :attr.percentage ? attr.percentage : 0
                    });
                },
                scroll : function(){
                    var scrollTopTmp = document.documentElement.scrollTop || document.body.scrollTop;
                    this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    var offsetBottom = this.scrollTop + this.windowHeight;
                    if(this.settings.parent_move){
                        this.wrapperUpdate(this.scrollTop);
                    }
                    for (var i = 0; i < this.Targets.length; i++) {
                        this.targetsUpdate(this.Targets[i]);
                    }
                },
                animate : function(){
                    this.scroll();
                    this.scrollId = requestAnimationFrame(this.animate.bind(this));
                },
                wrapperUpdate : function(){

                    this.wapperOffset += (this.scrollTop - this.wapperOffset) * this.settings.wrapperSpeed;
                    this.wrapper.style.transform = 'translate3d(' + 0 + ',' +  Math.round(-this.wapperOffset* 100) / 100 + 'px ,' + 0 + ')';
                },
                targetsUpdate : function(target){
                    var wH = $(window).height();
                    target.offsetTop = $(target.elm).offset().top;
                    target.top += ((this.scrollTop - target.offsetTop + (wH-target.hei)/2) * Number(this.settings.targetSpeed) * Number(target.speedY) - target.top) * this.settings.targetPercentage;
                    target.left += ((this.scrollTop - target.offsetTop + (wH-target.hei)/2) * Number(this.settings.targetSpeed) * Number(target.speedX) - target.left) * this.settings.targetPercentage;
                    var targetOffsetTop = ( parseInt(target.percentage) - target.top - parseInt(target.offset) );
                    var offsetY = Math.round(targetOffsetTop * -100) / 100;
                    var offsetX = 0;
                    if(target.type){
                        target.elm.style.opacity =  Math.abs(offsetY/10);
                    }else{
                        if(target.horizontal){
                            var targetOffsetLeft = ( parseInt(target.percentage) - target.left - parseInt(target.offset) );
                            offsetX = Math.round(targetOffsetLeft * -100) / 100;
                        }
                        if(this.settings.bgParallax){
                            if(target.horizontal){
                                $(target.elm).css({backgroundPosition:  offsetX +'px 50%'});
                            }else{
                                $(target.elm).css({backgroundPosition: '50% ' + offsetY + 'px'});
                            }
                        }else{
                            target.elm.style.transform = 'translate3d(' + offsetX + 'px ,' + offsetY + 'px ,' + 0 +')';
                        }
                    }
                },
                resize: function(){
                    var self = this;
                    self.windowHeight = (window.innerHeight || document.documentElement.clientHeight || 0);
                    if( parseInt(self.wrapper.clientHeight) != parseInt(document.body.style.height)){
                        document.body.style.height = self.wrapper.clientHeight + 'px';
                    }
                    self.resizeId = requestAnimationFrame(self.resize.bind(self));
                },
                attachEvent : function(){
                    var self = this;
                    window.addEventListener('resize',(function(){
                        if(!self.isResize){
                            cancelAnimationFrame(self.resizeId);
                            cancelAnimationFrame(self.scrollId);
                            self.isResize = true;
                            setTimeout((function(){
                                self.isResize = false;
                                self.resizeId = requestAnimationFrame(self.resize.bind(self));
                                self.scrollId = requestAnimationFrame(self.animate.bind(self));
                            }),200);
                        }
                    }));

                }
            };
            window.scrolly = new scrolly();
            return scrolly;
        },


        //手机端判断触摸滑动方向
        touchMove:function (el,call_right,call_left,call_up,call_down) {
            var self  = this;
            if(self.isPc) return false;
            var move = {};
            el.on('touchstart',function(e){
                //获取接触屏幕时的X和Y
                move.endX = 0;
                move.endY = 0;
                move.startX = e.originalEvent.changedTouches[0].pageX;
                move.startY = e.originalEvent.changedTouches[0].pageY;
            });
            el.on('touchmove',function(e) {
                //获取滑动屏幕时的X,Y
                move.endX = e.originalEvent.changedTouches[0].pageX;
                move.endY = e.originalEvent.changedTouches[0].pageY;
            });
            el.on('touchend',function(e) {
                var distanceX = null;
                var distanceY = null;
                //获取滑动屏幕时的X,Y
                if(move.endX ==0 || move.endY ==0){
                    distanceX = 0;
                    distanceY = 0;
                }else{
                    distanceX = move.endX - move.startX;
                    distanceY = move.endY - move.startY;
                }
                if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 50) {
                    self.appDirection='left';
                    if( call_left) { call_left(); }
                }
                else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < (-50)) {
                    self.appDirection='right';
                    if( call_right) { call_right(); }
                }
                else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 50) {
                    self.appDirection='up';
                    if( call_up ) { call_up(); }
                }
                else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < (-50)) {
                    self.appDirection='down';
                    if( call_down ) { call_down(); }
                }
            });
        },
        
    };

    window.base = new Tfn();

})(jQuery, window, document);

base.init();


$.fn.RangeSlider = function(cfg){
    this.sliderCfg = {
        min: cfg && !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null,
        max: cfg && !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
        step: cfg && Number(cfg.step) ? cfg.step : 1,
        callback: cfg && cfg.callback ? cfg.callback : null
    };

    var $input = $(this);
    var min = this.sliderCfg.min;
    var max = this.sliderCfg.max;
    var step = this.sliderCfg.step;
    var callback = this.sliderCfg.callback;

    $input.attr('min', min)
        .attr('max', max)
        .attr('step', step);

    $input.bind("input", function(e){
        $input.attr('value', this.value);
        $input.css( 'background-size', this.value + '% 100%' );

        if ($.isFunction(callback)) {
            callback(this);
        }
    });
};
var change = function($input) {
    /*内容可自行定义*/
    if($input.getAttribute('value')==100){
        $($input).parents('form').find('[type=submit]').addClass('yan-ok');
    }
}




